/**
 * 
 */
package gui.controller;

import java.io.File;
import java.io.IOException;

import javax.swing.JFileChooser;
import javax.swing.JPanel;

/**
 * @author Elisa Costante
 * 
 */
public class CustomizedFileChooser extends javax.swing.JFileChooser {

	private static final long serialVersionUID = 1L;

	public static File getFileToSave(JPanel panel) {
		// Create a file chooser
		try {
			JFileChooser fc = new JFileChooser(new File(".").getCanonicalPath());
			fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

			int returnVal = fc.showSaveDialog(panel);

			if (returnVal == JFileChooser.APPROVE_OPTION) {
				return (fc.getSelectedFile());

			}

		} catch (IOException e1) {
			e1.printStackTrace();

		}
		return null;
	}

	public static File getFileToOpen(JPanel panel) {
		// Create a file chooser
		try {
			JFileChooser fc = new JFileChooser(new File(".").getCanonicalPath());
			fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

			int returnVal = fc.showOpenDialog(panel);

			if (returnVal == JFileChooser.APPROVE_OPTION) {
				return (fc.getSelectedFile());

			}

		} catch (IOException e1) {
			e1.printStackTrace();

		}
		return null;
	}
}
